﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading.Tasks;

namespace YServer
{
    public class SerializationUtil
    {
        public static byte[] Serialization(object target){
            if (target == null) { return null; }

            MemoryStream ms = new MemoryStream();
            BinaryFormatter bf = new BinaryFormatter();

            bf.Serialize(ms, target);

            byte[] result = ms.GetBuffer();

            ms.Close();
            return result;
        }

        public static object DeSerialization(byte[] value) {
            MemoryStream ms = new MemoryStream(value);
            BinaryFormatter bf = new BinaryFormatter();

            object result= bf.Deserialize(ms);
            ms.Close();

            return result;

        }
    }
}
